<template>
  <div class="pagination-container">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="innerCurrentPage"
      :page-sizes="[10, 20, 30, 50]"
      :page-size="innerPageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'Pagination',
  props: {
    currentPage: {
      type: Number,
      required: true
    },
    pageSize: {
      type: Number,
      required: true
    },
    total: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      innerCurrentPage: this.currentPage,
      innerPageSize: this.pageSize
    }
  },
  watch: {
    currentPage(val) {
      this.innerCurrentPage = val
    },
    pageSize(val) {
      this.innerPageSize = val
    }
  },
  methods: {
    handleSizeChange(val) {
      this.innerPageSize = val
      this.innerCurrentPage = 1
      this.$emit('update:pageSize', val)
      this.$emit('update:currentPage', 1)
      this.$nextTick(() => {
        this.$emit('pagination-change')
      })
    },
    handleCurrentChange(val) {
      this.innerCurrentPage = val
      this.$emit('update:currentPage', val)
      this.$nextTick(() => {
        this.$emit('pagination-change')
      })
    }
  }
}
</script>

<style scoped>
.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style> 